// pages/show/show.js

var wxCharts = require("../../utils/wxcharts.js");
var yuelineChart=null;

Page({

  /**
   * 页面的初始数据
   */
  data: {
    imageWidth:0,
    items: [],
    gao: "",
    di: "",
    xue: "",

  },
    // 监听提交按钮
    removeStorageSync() {
      //使用数据库
      const db = wx.cloud.database() 
      const chucun =  db.collection('chucun')
      //添加一个data数据到chucun数据库中
      console.log(this.data.gao);
      let gao= parseInt(this.data.gao )
      console.log(gao);
      chucun.add({
      data:{
      //获取输入的内容
      gao: gao,
      di: Number(this.data.di),
      xue: Number(this.data.xue),
    }
  }).then(res=>{
  console.log(res)
}).catch(err=>{
  console.log(err)
})
let items = JSON.parse(JSON.stringify(this.data.items))
      // 设置新条目的id
      let newID = 1;
      if (items[0] !== undefined) {
        newID = items[0].id + 1;
       }
      // 将新条目更新到items中
      // 并将输入框的值清空
      items.unshift({
        id: newID,
        content: this.data.gao,
        content: this.data.di,
        content: this.data.xue,
        checked: false,
      });
      this.setData({
        items: items,
        gao: "",
        di: "",
        xue: "",
        
      })
    },

    // 已有代码
    checkboxChange(e) {
    },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
        },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
//在onShow方法中实现
    var windowWidth = 320;
  try {
   var res = wx.getSystemInfoSync();
   windowWidth = res.windowWidth;
  } catch (e) {
   console.error('getSystemInfoSync failed!');
  }
  yuelineChart = new wxCharts({ //一个月血压情况
   canvasId: 'yueEle',
   type: 'line',
   categories: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31'], //categories X轴
   animation: true,
   series: [{
    name: '低压',
    data: [88, 86, 89, 81, 80, 82, 89, 82, 88, 86, 84, 89, 88, 80, 83, 87, 83, 89, 83, 88, 89, 85, 84, 81, 85, 88, 85, 84, 89, 88, 87],
    format: function (val, name) {
     return val + '';
    }
   }, {
    name: '高压',
    data: [130, 136, 132,132, 137, 136, 132, 135, 138, 131, 138, 134, 130, 139, 137, 132, 135, 132, 138, 132, 135, 132, 139, 134, 134, 139, 138, 135, 135, 135, 136],
    format: function (val, name) {
     return val + '';
    }
   },{
    name: '血压',
    data: [110, 90, 130,132, 107, 97, 122,115, 128, 121, 98, 99, 110, 118,120, 109, 105, 103,110, 122, 135,120,98, 99, 100, 101, 98, 122, 105, 95, 115],
    format: function (val, name) {
     return val + '';
    },
  }
],
   xAxis: {
    disableGrid: true
   },
   yAxis: {
    title: '血压值',
    format: function (val) {
     return val;
    },
    /*max: 20,*/
    min: 50
   },
   width: windowWidth,
   height: 200,
   dataLabel: false,
   dataPointShape: true,
   extra: {
    lineStyle: 'curve'
   }
  });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})